package hflyeer.o2o.biz.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import hflyeer.o2o.biz.service.ShopCategoryService;
import hflyeer.o2o.model.dao.ShopCategoryDao;
import hflyeer.o2o.model.entity.ShopCategory;

@Service("ShopCategoryService")
public class ShopCategoryServiceImpl implements ShopCategoryService {

	@Autowired
	private ShopCategoryDao shopCategoryDao;

	@Override
	public List<ShopCategory> getShopCategorys() {
		return shopCategoryDao.queryForList();
	}

	@Override
	@Transactional
	public int batchAddShopCategory(List<ShopCategory> shopCategoryList) {
		for (ShopCategory shopCategory : shopCategoryList) {
			if (shopCategory.getPriority() == null || shopCategory.getPriority() == 0) {
				shopCategory.setPriority(0);
			}
			shopCategory.setCreateTime(new Date());
			shopCategory.setLastEditTime(new Date());
		}
		return shopCategoryDao.batchInsert(shopCategoryList);
	}

	@Override
	public int deleteShopCategory(int id) {
		return shopCategoryDao.delete(id);
	}

}
